package crp.core.analysis.app;

import crp.core.analysis.domain.services.ViewFlowSearcher;
import crp.core.shared.events.EventTopics;
import io.quarkus.vertx.ConsumeEvent;
import lombok.extern.slf4j.Slf4j;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;

@ApplicationScoped
@Slf4j
public class EventListener {
    private final ViewFlowSearcher viewFlowSearcher;

    @Inject
    public EventListener(ViewFlowSearcher viewFlowSearcher) {
        this.viewFlowSearcher = viewFlowSearcher;
    }

    @ConsumeEvent(value = EventTopics.VIEW_FLOW_CREATED, blocking = true)
    @Transactional
    public void onViewFlowCreated(String viewFlowId) throws InterruptedException {
        viewFlowSearcher.byId(viewFlowId)
                .ifPresent(viewFlow -> {
                    LOGGER.error("onViewFlowCreated {}", viewFlow.getId());
                });
    }
}
